import java.io.DataInput;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author VernHe
 * @date 2021年05月07日 15:49
 */
public class Solution_017 {
    public static void main(String[] args) {
        System.out.println(new Solution_017().letterCombinations(""));
    }

    static List<String> res = new ArrayList<>();
    public List<String> letterCombinations(String digits) {

        if (Objects.isNull(digits) || digits.length() == 0) {
            return res;
        }
        letterCombinations(digits,0,"");
        return res;
    }

    /**
     * 递归
     * @param digits    数字
     * @param index     位置，递归基用于判断是否该结束
     * @param s         路径
     * @return
     */
    public void letterCombinations(String digits, int index, String s) {
        // 递归基
        if (index == digits.length()) {
            // 走到头了，保存路径，并结束递归
            res.add(s);
            return;
        }
        // 递归调用
        char[] chars = getLetters(digits.charAt(index));
        for (int i = 0; i < chars.length; i++) {
            letterCombinations(digits,index + 1, s + chars[i]);
        }
        // 能到这里说明已经结束了
        return;
    }

    private char[] getLetters(char c) {
        switch (c) {
            case '2' : return  new char[]{'a','b','c'};
            case '3' : return  new char[]{'d','e','f'};
            case '4' : return  new char[]{'g','h','i'};
            case '5' : return  new char[]{'j','k','l'};
            case '6' : return  new char[]{'m','n','o'};
            case '7' : return  new char[]{'p','q','r','s'};
            case '8' : return  new char[]{'t','u','v'};
            case '9' : return  new char[]{'w','x','y','z'};
        }
        return null;
    }
}
